<template>
  <div>
    <div class="pltxt" v-if="setName!=undefined">{{setName}}</div>
    <van-field v-model="setValue_parent" clickable readonly @click="showPicker = true">
      <template #button>
        <van-button size="small" round @click="setTime($event)" class="setbtn">{{$t('Save')}}</van-button>
      </template>
    </van-field>
    <van-popup v-model="showPicker" round position="bottom">
      <van-datetime-picker
        v-model="currentTime"
        type="time"
        @cancel="showPicker = false"
        @confirm="onConfirm"
        :confirm-button-text="$t('OK')"
        :cancel-button-text="$t('Cancel')"
      />
    </van-popup>
  </div>
</template>

<script>
export default {
  props: ["setName", "setValue", "regH","regM"],
  data() {
    return {
      showPicker:false,
      setValue_parent: this.setValue,
      currentTime:''
    };
  },
  watch: {
    setValue(newVal) {
      this.setValue_parent = newVal;
    },
  },
  methods: {
    onConfirm(val){
      this.showPicker=false;
      this.setValue_parent=val;
    },
    setTime(e) {
      e.stopPropagation();
      let setValArr=this.setValue_parent.split(":");
      this.comm.bdSetDataPT(2, [{'reg':this.regH,'val':parseInt(setValArr[0])+''},{'reg':this.regM,'val':parseInt(setValArr[1])+''}]);
    },
  },
};
</script>

<style scoped lang="less">
</style>